#include "../../include/mysql_tool.h"
vector<string> mysql_tool::friend_list_query(string user_name)
{
    vector<string> user_friend;
    string id_se = "select user_id from user where user_name='';";
    id_se.insert(42, user_name);
    if (mysql_query(&mysql, id_se.c_str()))
    {
        cout << "sql语句执行失败" << endl;
    }
    else
    {
        cout << "sql语句执行成功" << endl;
    }
    MYSQL_RES *result = mysql_store_result(&mysql);
    MYSQL_ROW row = mysql_fetch_row(result);
    string user_id = row[0];
    string sql_sentence = "(SELECT u1.user_name AS friend_name, r1.relationship_status FROM relationship r1 JOIN `user` u1 ON r1.user_id_2 = u1.user_id WHERE r1.user_id_1 = ) UNION ALL (SELECT u2.user_name AS friend_name, r2.relationship_status FROM relationship r2 JOIN `user` u2 ON r2.user_id_1 = u2.user_id WHERE r2.user_id_2 = );";
    sql_sentence.insert(146, user_id);
    sql_sentence.insert(sql_sentence.size() - 2, user_id);
    if (mysql_query(&mysql, sql_sentence.c_str()))
    {
        cout << "sql语句执行失败" << endl;
        cout << "buzd" << endl;
    }
    else
    {
    }
    result = mysql_store_result(&mysql);
    while ((row = mysql_fetch_row(result)))
    {
        if (string(row[1]) == "1")
        {
            user_friend.push_back(row[0]);
        }
    }
    mysql_free_result(result);
    return user_friend;
}